
/**
 * tweet.h
 * 
 * Tweet holds a single tweet entry
 * 
 * Copyright (c) 2008 Harunobu Oyama <nobukichi at gmail.com>
 * Licensed under GNU GPL version 3
 *
 */

#ifndef		USER_STATUS_INCLUDED
#define		USER_STATUS_INCLUDED
	
#include	<set>
#include	<vector>
#include	<QDateTime>
#include	<QString>

class Tweet 
{
public:
	explicit Tweet(const QDateTime& timeStmp = QDateTime(), const QString& name = QString(), const QString& txt = QString(), const QString& imageUrl = QString());

	Tweet(const Tweet& rhs);
	Tweet& operator=(const Tweet& rhs);
	
	//! returns the date and time when the tweet was posted
	inline const QDateTime& timeStamp() const { return createdAt; }

	//! returns the name of the user who posted this
	inline const QString& userName() const { return screenName; }
	
	//! returns the entire tweet text including @<user>, if any
	inline const QString& statusText() const { return status; }

	//! sets the entire tweet text
	void setStatusText(const QString& txt);

	//! returns the url of the profile image
	inline const QString& imageUrl() const { return profileImageUrl; }

	//! returns user name specified with @<user> at the head of tweet text
	//! returns empty string if the statusText does not begin with @<user>
	QString atUser() const;

	//! returns tweet text after removing @user at the top
	QString tweetText() const;

	//! converts the tweet to a text in the following format (for serialization purpose)
	//! "yyyy/M/d hh:mm:ss\tscreenName\tprofileImageUrl\tsingleLineText"
	//! where "\\" and "\n" in text are encoded to "\\\\" and "\\n" in singleLineText  
	QString toString() const;

	//! decode a string encoded with Tweet#toString and return the Tweet
	//! if the string is not in the right format, it returns a Tweet with empty user name
	static Tweet fromString(const QString& str);

private:
	QDateTime createdAt;
	QString screenName;
	QString status;
	QString profileImageUrl;
};

//! operators required by std::set
bool operator==(const Tweet& lhs, const Tweet& rhs);
bool operator<(const Tweet& lhs, const Tweet& rhs);

typedef	std::vector<Tweet> TweetVector;
typedef	std::set<Tweet> TweetSet;

#endif	//	USER_STATUS_INCLUDED

